#include <iostream>
#include <cstdio>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <unistd.h>

const char* pathname = "/home/sxk/linux2/24_6_6";
int proj_id = 0x66;

int main()
{
    //得出key
    key_t key = ftok(pathname,proj_id);
    if(key < 0)
    {
        perror("ftok");
    }
    //创建共享内存
    int shmid = shmget(key,4096,IPC_CREAT);
    if(shmid < 0)
    {
        perror("shmget");
    }
    //打印出共享内存的key和shmid
    printf("key:   %x\n",key);
    printf("shmid: %d\n",shmid);
    sleep(2);
    //释放共享内存
    int t = shmctl(shmid,IPC_RMID,NULL);
    if(t < 0)
    {
        perror("shmctl");
    }
    return 0;
}